package net.hn.hnms.biz.common.activiti.builder;


import net.hn.hnms.biz.common.activiti.params.ProcessNodeParam;
import net.hn.hnms.biz.common.activiti.params.ProcessStepParam;

import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2022/8/4.
 *
 * @author ly
 * @desc: 流程步骤定义信息创建器
 */
public class ProcessStepDefinitionCreator {

    //流程节点定义信息
    private List<ProcessNodeParam> nodeParams = new ArrayList<>();

    public ProcessStepDefinitionCreator addNode(ProcessNodeParam nodeParam) {
        nodeParams.add(nodeParam);
        return this;
    }

    public ProcessStepDefinitionCreator addNodes(List<ProcessNodeParam> nodeParams) {
        nodeParams.addAll(nodeParams);
        return this;
    }

    /**
     * 根据传入的流程节点,将每个节点作为一个步骤
     * @return List<ProcessStepParam> 流程步骤集合
     */
    public List<ProcessStepParam> multi() {
        List<ProcessStepParam> stepParams = new ArrayList<>(nodeParams.size());
        for (ProcessNodeParam nodeParam : nodeParams) {
            ProcessStepParam stepParam = new ProcessStepParam();
            stepParam.addNode(nodeParam);
            stepParams.add(stepParam);
        }
        nodeParams = new ArrayList<>();
        return stepParams;
    }

    /**
     * 根据传入的流程节点,将传入的所有节点仅作为一个步骤
     * @return ProcessStepParam 单个流程步骤
     */
    public ProcessStepParam single() {
        ProcessStepParam stepParam = new ProcessStepParam();
        for (ProcessNodeParam nodeParam : nodeParams) {
            stepParam.addNode(nodeParam);
        }
        nodeParams = new ArrayList<>();
        return stepParam;
    }
}
